import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

let userInfo = uni.getStorageSync('userinfo');
let users = uni.getStorageSync('users');
let accounts = uni.getStorageSync('accounts');
let fundTypes = uni.getStorageSync('fundTypes');

const store = new Vuex.Store({
	state:{
		userInfo: userInfo || {},
		users: users || [],
		accounts: accounts || [],
		fundTypes: fundTypes || [],
		token: userInfo ?　userInfo.token　:　'',
		
	},
	mutations: {
		changeUserInfo(state, info) {
			uni.setStorageSync('token', info.token);
			uni.setStorageSync('userinfo', info);
			state.userInfo = info;
			state.token = info.token;
		},
		
		changeUsers(state, info) {
			state.users = info;
		},
		changeAccounts(state, info) {
			state.accounts = info;
		},
		changeFundTypes(state, info) {
			state.fundTypes = info;
		},
		logout(state){
			state.userInfo = null;
			state.token = null;
			uni.removeStorageSync('token');
			uni.removeStorageSync('userinfo');
		},
		
	},
	actions: {
		
	}
})

export default store